<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //预加载图片
        //回调
        // function loadImage(url, callback) {
        //     const img = document.createElement('img')
        //     img.src = url
        //     img.onload = () => { callback(undefined, img) }
        //     img.onerror = (e) => { console.log(e) }

        // }
        // loadImage('../../ajax/Classroom learning/webJavaScript/img/small/3.jpg', function (img) {
        //     document.body.append(img)
        // })


        //promise
        // function loadImage(url, callback) {
        //     return new Promise((resolve, reject) => {
        //         const img = document.createElement('img')
        //         img.src = url
        //         img.onload = () => { resolve(img) }
        //         img.onerror = (e) => { reject(new Error(`图片加载失败(${e.url})`)) }
        //     })
        // }
        // loadImage('../0419/作业/尝试这些代码的结果.png').then(img => {
        //     document.body.append(img)
        // })
        //     .then(() => loadImage('../0419/作业/尝试这些代码的结果.png'))
        //     .catch(e => {
        //         document.body.append(e)
        //     })

    </script>

    <!-- <script>
        function delay(ms) {
            return new Promise((resolve, reject) => {
                setTimeout(resolve, ms)
            })
        }
        const { body } = document
        function lights() {
            return delay(0)
                .then(() => body.style.backgroundColor = 'red')
                .then(() => delay(3000))
                .then(() => body.style.backgroundColor = 'yellow')
                .then(() => delay(1000))
                .then(() => body.style.backgroundColor = 'green')
                .then(() => delay(1000))
                .then(() => body.style.backgroundColor = 'yellow')
                .then(() => delay(1000))
                .then(() => body.style.backgroundColor = 'red')
                .then(() => delay(1000))
                .then(() => lights())
        }
        lights()
    </script> -->

    <!-- <script>
        function loadScript(url) {
            return new Promise((resolve, reject) => {
                const script = document.createElement('script')
                script.src = url
                script.onload = () => { resolve() }
                script.onerror = () => { reject(new Error('脚本加载失败' + url)) }
                document.head.append(script)
            })

        }
        loadScript('./fn.js')
            .then(() => fn())
            .catch(e => console.log(e))


        // fn()
    </script> -->




</body>

</html>